﻿using MathTutorPro.DAL;
using MathTutorPro.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace MathTutorPro.Data.DAL
{
    public class GroupChatMessageDal
    {
        private readonly AppDbContext _context;

        public GroupChatMessageDal(AppDbContext context)
        {
            _context = context;
        }

        public async Task AddMessageAsync(ChatGroupMessage message)
        {
            await _context.ChatGroupMessage.AddAsync(message);
            await _context.SaveChangesAsync();
        }

        public async Task<IEnumerable<ChatGroupMessage>> GetMessagesByGroupAsync(int groupId)
        {
            return await _context.ChatGroupMessage
                .Where(m => m.ChatGroupId == groupId && !m.IsDelete)
                .OrderBy(m => m.SentTime)
                .ToListAsync();
        }
    }
}
